package com.wujiansima.renyisima.demo.demo4;

public class MyRunnable implements Runnable {
    private int ticket = 100;
    private Object obj = new Object();
    @Override
    public void run() {
        while (true) {
            synchronized (MyRunnable.class){
                if (ticket <= 0){
                    break;
                }else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "正在卖票，还剩" + --ticket + "张票");
                }
            }
        }
    }
}
